//package com.cq.hd.order.config;
//
//import org.springframework.cache.annotation.CachingConfigurerSupport;
//import org.springframework.cache.annotation.EnableCaching;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.cache.RedisCacheConfiguration;
//import org.springframework.data.redis.cache.RedisCacheManager;
//import org.springframework.data.redis.cache.RedisCacheWriter;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.serializer.*;
//
//import java.time.Duration;
//
///**
// * @description: TODO
// * @author: mYunYu
// * @date: 2021/8/15 22:17
// * @version: v1.0
// */
//@Configuration
//@EnableCaching
//public class RedisConfig extends CachingConfigurerSupport {
//
//    /**
//     * @Description: 配置CacheManager
//     * @Param: [redisConnectionFactory]
//     * @Return: org.springframework.data.redis.cache.RedisCacheManager
//     * @Auther: mYunYu
//     * @Date: 2021/8/15 23:40
//     */
//    @Bean
//    public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
//        RedisCacheWriter writer = RedisCacheWriter.lockingRedisCacheWriter(redisConnectionFactory);
//
//        RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
//                .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
//                .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new Jackson2JsonRedisSerializer<>(Object.class)))
//                .computePrefixWith(name -> name + ":")
//                //设置缓存有效期10s
//                .entryTtl(Duration.ofMinutes(10));
//
//        return RedisCacheManager.builder(writer).cacheDefaults(config).build();
//    }
//
//    /**
//     * @Description: RedisTemplate配置
//     * @Param: [redisConnectionFactory]
//     * @Return: org.springframework.data.redis.core.RedisTemplate<java.lang.String,java.lang.Object>
//     * @Auther: mYunYu
//     * @Date: 2021/8/15 23:40
//     */
//    @Bean
//    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
//        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
//        redisTemplate.setConnectionFactory(redisConnectionFactory);
//        //设置序列化策略
//        redisTemplate.setKeySerializer(new StringRedisSerializer());
//        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
//        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
//        redisTemplate.afterPropertiesSet();
//        return redisTemplate;
//    }
//
//}
